<?xml version="1.0" encoding="utf-8"?>
<Content xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:blueonionsoftware-com:bloget:runtime:data">
  <text>From a &lt;a href="http://blogs.msdn.com/AdiOltean/archive/2005/02/16/374160.aspx"&gt;Microsoft Web log&lt;/a&gt;

Here is a little known feature of our beloved CMD.EXE. It is extremely easy to evaluate an arithmetic expression! All it takes is a five characters. Just type set /a followed by your expression.

Here is an example:

&lt;pre&gt;
    E:\&gt;set /a 1+1
    2
&lt;/pre&gt;

Or, if you want, you can convert hex numbers to decimal:

&lt;pre&gt;
    E:\&gt;set /a 0x8000ffff
    -2147418113
&lt;/pre&gt;

Or even more, you can use and assign variables:
&lt;pre&gt;
    E:\&gt;set /a i=1+2
    3
    E:\&gt;set /a j=i+1
    4
&lt;/pre&gt;
You can use this everywhere, for example in loops:
&lt;pre&gt;
    E:\&gt;for /L %i in (1,1,10) do @set /a 1^&lt; ^&lt;%i &amp; echo.
    2
    4
    8
    16
    32
    64
    128
    256
    512
    1024
&lt;/pre&gt;
So what operators can you use? That's easy to figure out. Here is a snippet from the "set /?" help text...

    The /A switch specifies that the string to the right of the equal sign
    is a numerical expression that is evaluated.  The expression evaluator
    is pretty simple and supports the following operations, in decreasing
    order of precedence:

&lt;/pre&gt;&lt;pre&gt;
        ()                  - grouping
        ! ~ -               - unary operators
        * / %               - arithmetic operators
        + -                 - arithmetic operators
        &lt; &lt; &gt;&gt;               - logical shift
        &amp;                   - bitwise and
        ^                   - bitwise exclusive or
        |                   - bitwise or
        = *= /= %= += -=    - assignment
          &amp;= ^= |= &lt; &lt;= &gt;&gt;=
        ,                   - expression separator
&lt;/pre&gt;

    If you use any of the logical or modulus operators, you will need to
    enclose the expression string in quotes.  Any non-numeric strings in the
    expression are treated as environment variable names whose values are
    converted to numbers before using them.  If an environment variable name
    is specified but is not defined in the current environment, then a value
    of zero is used.  This allows you to do arithmetic with environment
    variable values without having to type all those % signs to get their
    values.  If SET /A is executed from the command line outside of a
    command script, then it displays the final value of the expression.  The
    assignment operator requires an environment variable name to the left of
    the assignment operator.  Numeric values are decimal numbers, unless
    prefixed by 0x for hexadecimal numbers, and 0 for octal numbers.
    So 0x12 is the same as 18 is the same as 022. Please note that the octal
    notation can be confusing: 08 and 09 are not valid numbers because 8 and
    9 are not valid octal digits.
</text>
  <last_update>2007-10-04T00:52:27.6380806Z</last_update>
  <source_title />
  <source_link />
  <comments>
    <comment>
      <id>73a01726-974c-433d-bc9a-64e3bc43ea03</id>
      <title />
      <date>2005-02-16T10:02:36</date>
      <author>chris.o</author>
      <email />
      <text>Nifty, just nifty.</text>
    </comment>
  </comments>
  <references />
  <attachments />
</Content>